package my.test.csdn.weixin_43767015.basic.ch12.transaction.declarative.annotation.eachcall.service;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
public class EachCall {
    /**
     * jdbc模版，用于操作数据库
     */
    @Resource
    private JdbcTemplate jdbcTemplate;
    
    public void m1() {
        m2();
    }
    
    @Transactional
    public void m2() {
        String sql = "insert into tx_study (name,age) values (?,?)";
        jdbcTemplate.update(sql, "EachCall", 30);
        //抛出一个RuntimeException
        throw new RuntimeException();
    }
}
